//
//  EditShopBox.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/15.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "EditShopBox.h"
#import "MeatShopCartTableViewCell.h"


//展示Viwe高度
#define BoxW  KScreenWidth - 57
#define BoxH 464

@interface EditShopBox()

@property (nonatomic, strong) UIView *mContentView;

@property (nonatomic, strong) UILabel *titleLab; //标题
@property (nonatomic, strong) UILabel *planLab1; //金钱
@property (nonatomic, strong) UILabel *planLab2; //金钱
@property (nonatomic, strong) UILabel *planLab3; //金钱


@property (nonatomic, strong) UIButton *closeBtn; //关闭按钮
@property (nonatomic, strong) UIButton *okBtn;


@end


@implementation EditShopBox

- (instancetype)init{
    self = [super initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    if (self) {
        [self setupContent];
        
    }
    return self;
}

- (void)setupContent{
    
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    {
        _mContentView.size = CGSizeMake(BoxW, BoxH);
        _mContentView.center = self.center;
        _mContentView.mj_y -= 70;
        _mContentView.mj_x = 35;
    }
    
    
    {
        _titleLab.size = CGSizeMake(BoxW, 34);
        _titleLab.mj_x = 0;
        _titleLab.mj_y = 158;

    }
    
    
    {
        _planLab1.size = CGSizeMake(BoxW - 70, 45);
        [_planLab1 sizeToFit];
        _planLab1.mj_x = 42;
        _planLab1.mj_y = _titleLab.bottom + 8;

    }
    
    {
        _planLab2.size = CGSizeMake(BoxW - 70, 66);
        [_planLab2 sizeToFit];
        _planLab2.mj_x = 42;
        _planLab2.mj_y = _planLab1.bottom + 15;

    }

    {
        _planLab3.size = CGSizeMake(BoxW - 70, 22);
        [_planLab3 sizeToFit];
        _planLab3.mj_x = 42;
        _planLab3.mj_y = _planLab2.bottom + 15;
    }
    
    {
        _okBtn.size = CGSizeMake(BoxW -60, 44);
        _okBtn.mj_x = 30;
        _okBtn.mj_y = BoxH - 74;
    }

    
    {
        //关闭按钮
        _closeBtn.size = CGSizeMake(50, 50);
        _closeBtn.mj_x = (_mContentView.width - _closeBtn.width)/2.0;
        _closeBtn.mj_y = _mContentView.height + 21;

    }
    
}


- (void)showView{
    
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window addSubview:self];
    
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissView)]];
    [self addSubview:self.mContentView];
    
    CGAffineTransform firstTransform = CGAffineTransformScale(self.transform, 0.1, 0.1);
    [_mContentView setTransform:firstTransform];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.25];
    _mContentView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
    [UIView commitAnimations];
    
}


- (void)dismissView{
    self.alpha = 0;
    self.mContentView.alpha = 0;
    [self removeAllSubviews];
    [self.mContentView removeAllSubviews];
}


#pragma mark - setter and getter
- (UIView *)mContentView{
    if (!_mContentView) {
        _mContentView = [UIView new];
        
        UIImage *image = [UIImage imageNamed:@"meat_separater_bg"];
        _mContentView.layer.contents = (__bridge id)image.CGImage;
        
        
        [_mContentView addSubview:self.closeBtn];
        
        [_mContentView addSubview:self.titleLab];
        [_mContentView addSubview:self.planLab1];
        [_mContentView addSubview:self.planLab2];
        [_mContentView addSubview:self.planLab3];
        
        [_mContentView addSubview:self.okBtn];


    }
    
    return _mContentView;
}



- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.text = @"您是否确认分割方案？";
        _titleLab.textColor = UIColorFromRGB(0x262626);
        _titleLab.font = mFont(20);
        _titleLab.textAlignment = NSTextAlignmentCenter;
    }
    
    return _titleLab;
}


- (UILabel *)planLab1{
    if (!_planLab1) {
        _planLab1 = [UILabel new];
        _planLab1.textColor = UIColorFromRGB(0x808080);
        _planLab1.text = @"1. 选择分割方案后同时开通您在本部落的肉铺，可在肉市-我的肉铺进入查看";
        NSMutableAttributedString *aims = [_planLab1.text getParagraphAttributedStringWithLineSpacing: 8];
        _planLab1.attributedText = aims;

        _planLab1.numberOfLines = 0;
        _planLab1.font = mFont(13);
    }
    return _planLab1;
}

- (UILabel *)planLab2{
    if (!_planLab2) {
        _planLab2 = [UILabel new];
        _planLab2.textColor = UIColorFromRGB(0x808080);
        _planLab2.text = @"2. 您可在自己的肉铺中预留您的猪肉并销售其余部分，请到肉市-我的肉铺-我的货架，进行设置";
        NSMutableAttributedString *aims = [_planLab2.text getParagraphAttributedStringWithLineSpacing: 8];
        _planLab2.attributedText = aims;

        _planLab2.numberOfLines = 0;
        _planLab2.font = mFont(13);
    }
    return _planLab2;
}

- (UILabel *)planLab3{
    if (!_planLab3) {
        _planLab3 = [UILabel new];
        _planLab3.textColor = UIColorFromRGB(0x808080);
        _planLab3.text = @"3.在指定区域内，平台包邮";
        _planLab3.font = mFont(13);
        _planLab3.numberOfLines = 0;
    }
    return _planLab3;
}


- (UIButton *)okBtn{
    
    if (!_okBtn) {
        _okBtn = [UIButton makeButtonWithText:@"确认" textColor:KWhiteColor font:mMediumFont(16) textAliment:1 cornerRadius:5];
        [_okBtn setBackgroundImage:[UIImage imageNamed:@"btn_nomal_bg"] forState:UIControlStateNormal];

        @weakify(self);
        _okBtn.tapBlock = ^{
            @strongify(self);
            [self dismissView];
            
            if (self.dealOkBlock) {
                self.dealOkBlock();
            }
        };
    }
    return _okBtn;
}

- (UIButton *)closeBtn{
    if (!_closeBtn) {
        
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setImage:[UIImage imageNamed:@"meat_separater_close"] forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _closeBtn;
}



@end
